package com.bupt.liutong.admin.sch.bo;

import javax.servlet.http.HttpServletRequest;

import com.bupt.liutong.admin.core.base.FileUploader;
import com.bupt.liutong.admin.core.dao.ConfigDao;
import com.bupt.liutong.admin.core.dto.Config;
import com.bupt.liutong.admin.core.form.ConfigForm;
import com.bupt.liutong.admin.sch.dao.IntroPhotoDao;
import com.bupt.liutong.admin.sch.form.IntroForm;
import com.bupt.liutong.util.BeanUtils;

public class IntroBo {
	private ConfigDao configDao;
	private IntroPhotoDao introPhotoDao;
	private FileUploader fileUploader;
	
	public String getIntro(){
		return configDao.getConfigByCode("sch_intro");
	}
	
	public String getBriefIntro(){
		return configDao.getConfigByCode("sch_brief_intro");
	}
	
	public void updateIntro(IntroForm introForm, HttpServletRequest request) {
		Config config = new Config();
		BeanUtils.copyProperties(config, introForm);
		config.setCode("sch_intro");
		configDao.updateConfigByCode(config);
		
		// update old photo
		fileUploader.updateImages(introForm, introPhotoDao, request);
		// upload new photo
		fileUploader.uploadImages(introForm, introPhotoDao, request);
	}
	
	public void updateBriefIntro(ConfigForm configForm) {
		Config config = new Config();
		BeanUtils.copyProperties(config, configForm);
		config.setCode("sch_brief_intro");
		configDao.updateConfigByCode(config);
	}

	public void setConfigDao(ConfigDao configDao) {
		this.configDao = configDao;
	}

	public void setIntroPhotoDao(IntroPhotoDao introPhotoDao) {
		this.introPhotoDao = introPhotoDao;
	}

	public void setFileUploader(FileUploader fileUploader) {
		this.fileUploader = fileUploader;
	}
}
